<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>在线考试平台</title>
    <link rel="shortcut icon" href="../images/exam.png" type="image/x-icon">
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">

</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15" style="background: #f7f8fc">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">待批阅列表</div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="no_review_exam" lay-filter="no_review_exam"></table>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="do_review">审阅</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<script type="text/javascript"  src="../lib/layui/layui.js"></script>
<script type="text/javascript" src="../js/xadmin.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script>
    layui.use(['element', "form", 'jquery', 'layer'], function () {
        const form = layui.form;
        const $ = layui.jquery;
        const layer = layui.layer;
        const element = layui.element;
        get_no_review_exam()
    });


    function get_no_review_exam() {
        layui.use(["form", 'jquery', 'layer', 'table'], function () {
            const $ = layui.jquery;
            const layer = layui.layer;
            const table = layui.table;
            table.render({
                elem: '#no_review_exam'
                , url: 'get_no_review_exam'
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , title: '试卷表'
                , cols: [[
                    {field: 'pr_id', title: '序号', sort: true}
                    , {field: 'e_name', title: '考试名', templet: '<div>{{d.examUser.exam.e_name}}</div>'}
                    , {field: 's_name', title: '所属科目', templet: '<div>{{d.examUser.exam.subject.s_name}}</div>'}
                    , {field: 'u_id', title: '用户id', templet: '<div>{{d.examUser.u_id}}</div>'}
                    , {field: 'pr_state', title: '审阅状态'}
                    // , {field: 'sa_level', title: '难度等级', templet: '<div>{{d.sysAuthority.a_authority}}</div>'}
                    , {title: '操作', align: 'center', toolbar: '#barDemo'}
                ]]
                , page: {				//分页设置
                    limit: 10,		//默认每一页显示数量
                    limits: [5, 10, 20, 30, 40, 50]		//可选择每页显示的数量
                }
                , parseData: function (res) { //res 即为原始返回的数据
                    var current_pages;
                    //第一次显示的时候this.page=true，把这种情况单独列出
                    if (this.page === true) current_pages = 1;
                    else current_pages = this.page.curr;
                    //根据分页要求选出需要显示的数据
                    let data = res.result.slice(this.limit * (current_pages - 1), this.limit * current_pages);
                    //alert(JSON.stringify(data));
                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.result.length,
                        "data": data
                    }
                }
            });

            //监听行工具事件
            table.on('tool(no_review_exam)', function (obj) {
                let data = obj.data;
                console.log(obj)
                if (obj.event === 'do_review') {
                    if (data.pr_state === "已审阅") {
                        layer.alert("已经审阅", {icon: 6})
                    } else {
                        layer.confirm('确认审阅？', {icon: 0}, function () {
                            parent.xadmin.add_tab('审批试卷', 'review_exam?eu_id=' + data.eu_id);
                        });
                    }
                }
            });

        });
    }
</script>
</html>